package com.book.controller;

import com.book.po.BookType;
import com.book.service.bookTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.List;

@Controller
@RequestMapping("/bookType")
public class boolTypeController {
    @Autowired
    private bookTypeService bookTypeService;

    @RequestMapping("/bookType_select")
    public String book_select(RedirectAttributes model, BookType bookType){
        List<BookType> bookTypes = bookTypeService.bookType_select(bookType.getTypeName());
        if (bookTypes.size()>=1){
            model.addFlashAttribute("bookTypes",bookTypes);
            model.addFlashAttribute("msg","");
            return "redirect:/manage/bookTypeManage";
        }else {
            model.addFlashAttribute("msg","没有查找到书籍类型！");
            return "redirect:/manage/bookTypeManage";
        }
    }

    @RequestMapping("/bookType_insert")
    public String book_insert(RedirectAttributes  model, BookType bookType){
        String msg = bookTypeService.bookType_insert(bookType);
        model.addFlashAttribute("msg",msg);
        return "redirect:/manage/bookTypeManage";
    }

    @RequestMapping("/bookType_update")
    public String book_update(RedirectAttributes  model, BookType bookType){
        String msg = bookTypeService.bookType_update(bookType);
        model.addFlashAttribute("msg",msg);
        return "redirect:/manage/bookTypeManage";
    }

    @RequestMapping("/bookType_delete")
    public String book_delete(RedirectAttributes  model, Integer typeId){
        String msg = bookTypeService.bookType_delete(typeId);
        model.addFlashAttribute("msg",msg);
        return "redirect:/manage/bookTypeManage";
    }
}
